package com.eduhzy.ttw.teacher.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.blankj.utilcode.util.ObjectUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.LinkBack;
import com.eduhzy.ttw.commonsdk.entity.PlatformNoticeData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.commonsdk.http.CommonApi;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.mvp.contract.VerifyMessageContract;
import com.eduhzy.ttw.teacher.mvp.model.VerifyMessageModel;
import com.google.gson.reflect.TypeToken;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-7-20 17:16:22
 */
@Module
public abstract class VerifyMessageModule {

    @Binds
    abstract VerifyMessageContract.Model bindVerifyMessageModel(VerifyMessageModel model);

    @ActivityScope
    @Provides
    static List<PlatformNoticeData> provideList() {
        return new ArrayList<>();
    }


    @ActivityScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManager(VerifyMessageContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }

    @ActivityScope
    @Provides
    static BaseQuickAdapter<PlatformNoticeData, AutoBaseViewHolder> provideActivityAdapter(List<PlatformNoticeData> list) {
        return new BaseQuickAdapter<PlatformNoticeData, AutoBaseViewHolder>(R.layout.rv_item_verify_message, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, PlatformNoticeData item) {
                if(ObjectUtils.isNotEmpty(item.getLinkBack())){
                    List<LinkBack> lists = ArmsUtils.obtainAppComponentFromContext(mContext).gson().fromJson(item.getLinkBack(), new TypeToken<List<LinkBack>>() {
                    }.getType());
                    LinkBack linkBack = lists.get(0);
                    LinkBack.ParamsBean params = linkBack.getParams();
                    Glide.with(helper.itemView.getContext())
                            .load(CommonApi.APP_AVATAR + params.getAccessUserId())
                            .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                            .into((ImageView) helper.getView(R.id.iv_avatar));
                }
                QMUIRoundButton button = helper.getView(R.id.btn_accept);
                helper.setVisible(R.id.btn_accept, ObjectUtils.isNotEmpty(item.getLinkBack()));
                helper.addOnClickListener(R.id.btn_accept);
                //状态：0待审核 1审核通过 2审核不通过 -1删除
                switch (item.getDealStatus()) {
                    case 0:
                        button.setText("接受");
                        button.setSelected(true);
                        break;
                    case 1:
                        button.setText("已通过");
                        button.setSelected(false);
                        break;
                    case 2:
                        button.setText("已拒绝");
                        button.setSelected(false);
                        break;
                    default:
                }
                helper.setText(R.id.tv_name, item.getTitle());
                helper.setText(R.id.tv_content, item.getContent());

            }
        };
    }

}